package com.qijian.common.utils.sync;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class KingDeeInventoryData extends BaseKingDee {


    /**
     * 简单生产退料单
     *
     * @return kingdee数据
     */
    public List<JSONObject> simpleItemBack(String condition) {
        String[] main_fields = new String[]{
                "FID", "FBillNo", "FDate", "FWorkShopId.FName", "FBillType.FName", "FBizType", "FCurrId.FName"
                , "FStockerGroupId.FName", "FStockerId", "FStockerId.FName", "FReturnerId", "FReturnerId.FName"
                , "F_ora_Text", "FDescription"
                , "FCancelStatus", "FDocumentStatus", "FCreatorId.FName", "FCreateDate", "FModifierId.FName", "FModifyDate"
                , "FApproverId.FName", "FApproveDate"
        };
        String[] detail_fields = new String[]{
                "FEntity_FEntryID", "FSrcBillType", "FSrcInterId", "FSrcEntryId", "FSrcBillNo"
                , "FMaterialId", "FMaterialId.FName", "FMaterialId.FNumber", "FUnitID.FName", "FSecUnitId.FName"
                , "FAPPQty", "FQty,FSecStockQty", "FReturnType", "FReturnReason","FPrice","FAmount"
                , "FLot", "FProduceDate", "FExpiryDate", "FStockId", "FStockId.FName", "FSTOCKLOCID.FF100014", "FSTOCKLOCID.FF100014.FNAME"
                , "FInStockDate", "F_ora_Base.F_ORA_TEXT", "FEntrtyMemo"

                , "FAUXPROPID.FF100001.fdatavalue"
                , "FAUXPROPID.FF100002.fdatavalue"
                , "FAUXPROPID.FF100003"
                , "FAUXPROPID.FF100004"
                , "FAUXPROPID.FF100005.fdatavalue"
                , "FAUXPROPID.FF100006.fdatavalue"
                , "FAUXPROPID.FF100007"
                , "FAUXPROPID.FF100008"
                , "FAUXPROPID.FF100009"
                , "FAUXPROPID.FF100011"
                , "FAUXPROPID.FF100013"
                , "FAUXPROPID.FF100015.fdatavalue"
                , "FAUXPROPID.FF100016.fdatavalue"
                , "FAUXPROPID.FF100017.fdatavalue"
                , "FAUXPROPID.FF100018.fdatavalue"
                , "FAUXPROPID.FF100019.fdatavalue"
                , "FAUXPROPID.FF100020.fdatavalue"
                , "FAUXPROPID.FF100021"
                , "FAUXPROPID.FF100022"
                , "FAUXPROPID.FF100023"
        };

        String where = "FStockOrgId = 100121"
                + (StringUtils.isNotBlank(condition) ? AND + condition : "");
        return super.getDataJson("SP_ReturnMtrl", ArrayUtils.addAll(main_fields, detail_fields), where);
    }

    public List<JSONObject> itemBack(String condition) {
        String[] main_fields = new String[]{
                "FID" , "FBillNo", "FDate"
                , "FBillType.FName", "FBillType", "FCurrId.FName"
                , "FStockerId", "FStockerId.FName", "FReturnerId", "FReturnerId.FName"
                , "F_ora_Text", "FDescription"
                , "FCancelStatus", "FDocumentStatus", "FCreatorId.FName", "FCreateDate", "FModifierId.FName", "FModifyDate"
                , "FApproverId.FName", "FApproveDate"
        };
        String[] detail_fields = new String[]{
                "FEntity_FEntryID", "FSrcBillType", "FEntrySrcInterId", "FEntrySrcEnteryId", "FSrcBillNo"
                , "FMaterialId", "FMaterialId.FName", "FMaterialId.FNumber", "FUnitID.FName", "FSecUnitId.FName"
                , "FAPPQty", "FQty,FSecStockQty", "FReturnType", "FReturnReason","FPrice","FAmount"
                , "FLot", "FProduceDate", "FExpiryDate", "FStockId", "FStockId.FName", "FSTOCKLOCID.FF100014", "FSTOCKLOCID.FF100014.FNAME"
                , "F_ora_Base.F_ORA_TEXT", "FEntrtyMemo"
                , "FWorkShopId1.FName"
                , "FAUXPROPID.FF100001.fdatavalue"
                , "FAUXPROPID.FF100002.fdatavalue"
                , "FAUXPROPID.FF100003"
                , "FAUXPROPID.FF100004"
                , "FAUXPROPID.FF100005.fdatavalue"
                , "FAUXPROPID.FF100006.fdatavalue"
                , "FAUXPROPID.FF100007"
                , "FAUXPROPID.FF100008"
                , "FAUXPROPID.FF100009"
                , "FAUXPROPID.FF100011"
                , "FAUXPROPID.FF100013"
                , "FAUXPROPID.FF100015.fdatavalue"
                , "FAUXPROPID.FF100016.fdatavalue"
                , "FAUXPROPID.FF100017.fdatavalue"
                , "FAUXPROPID.FF100018.fdatavalue"
                , "FAUXPROPID.FF100019.fdatavalue"
                , "FAUXPROPID.FF100020.fdatavalue"
                , "FAUXPROPID.FF100021"
                , "FAUXPROPID.FF100022"
                , "FAUXPROPID.FF100023"
        };

        String where = "FStockOrgId = 100121"
                + (StringUtils.isNotBlank(condition) ? AND + condition : "");
        return super.getDataJson("PRD_ReturnMtrl", ArrayUtils.addAll(main_fields, detail_fields), where);
    }

    /**
     * 销售出库
     *
     * @param c
     * @return
     */
    public List<JSONObject> getSaleOutbound(String c) {
        String[] main_fields = new String[]{"FID", "FBillNo", "FBillTypeID.FName", "FCustomerID", "FCustomerID.FName"
                , "FDeliveryDeptID", "FDeliveryDeptID.FName,FStockerID,FStockerID.FName", "FDate", "FSettleCurrID.FName", "FExchangeRate"
                , "FReceiveAddress,FHeadLocationId.FName,FNote"

                , "FCancelStatus", "FDocumentStatus", "FCreatorId.FName", "FCreateDate", "FModifierId.FName", "FModifyDate"
                , "FApproverId.FName", "FApproveDate"
        };
        String[] detail_fields = new String[]{"FEntity_FENTRYID", "FSOEntryId", "F_ora_Text", "FSrcType"
                , "FEntity_Link_FSBillId", "FEntity_Link_FSId", "FLOT.FName", "FMaterialID", "FMaterialID.FName", "FMaterialID.FNumber"

                , "FUnitID.FName", "FAuxUnitID.FName", "FRealQty", "FExtAuxUnitQty"
                , "FTaxPrice", "FPrice", "FAllAmount", "FAllAmount_LC", "FAmount", "FAmount_LC", "FDiscountRate", "FEntryTaxRate"
                , "FBillTaxAmount", "FBillTaxAmount_LC", "FStockID", "FStockID.FName", "FCostPrice", "FSalCostPrice"
                , "FEntryCostAmount", "FCostAmount_LC", "FEntrynote"
                , "FAUXPROPID.FF100001.fdatavalue"
                , "FAUXPROPID.FF100002.fdatavalue"
                , "FAUXPROPID.FF100003"
                , "FAUXPROPID.FF100004"
                , "FAUXPROPID.FF100005.fdatavalue"
                , "FAUXPROPID.FF100006.fdatavalue"
                , "FAUXPROPID.FF100007"
                , "FAUXPROPID.FF100008"
                , "FAUXPROPID.FF100009"
                , "FAUXPROPID.FF100011"
                , "FAUXPROPID.FF100013"
                , "FAUXPROPID.FF100015.fdatavalue"
                , "FAUXPROPID.FF100016.fdatavalue"
                , "FAUXPROPID.FF100017.fdatavalue"
                , "FAUXPROPID.FF100018.fdatavalue"
                , "FAUXPROPID.FF100019.fdatavalue"
                , "FAUXPROPID.FF100020.fdatavalue"
                , "FAUXPROPID.FF100021"
                , "FAUXPROPID.FF100022"
                , "FAUXPROPID.FF100023"
        };
        String where = "FStockOrgId = 100121"
                + (StringUtils.isNotBlank(c) ? AND + c : "");
        return super.getDataJson("SAL_OUTSTOCK", ArrayUtils.addAll(main_fields, detail_fields), where);
    }

    /**
     * 出库申请（领料申请）
     *
     * @param c
     * @return
     */
    public List<JSONObject> getOutboundApply(String c) {

        String[] main_fields = new String[]{"FID", "FBillNo", "FBillTypeID.FName", "FDate"
                , "FEntity_Link_FSBillId", "FEntity_Link_FSTableName", "FStockOrgId", "FStockOrgId.FName"
                , "FDeptId", "FDeptId.FName", "FNote", "FCloseStatus", "FCloseDate", "FCloserId.FName"
                , "FCancelStatus", "FDocumentStatus", "FCreatorId.FName", "FCreatorId.FUserAccount", "FCreateDate", "FModifierId.FName", "FModifyDate"
                , "FApproverId.FName", "FApproveDate"
        };
        String[] detail_fields = new String[]{"FEntity_FEntryID", "FMaterialId", "FMaterialId.FName", "FMaterialId.FNumber"
                , "FUnitID.FName", "FExtAuxUnitId.FName", "FQty", "F_ora_Qty", "F_ora_Qty1", "FExtAuxUnitQty"
                , "F_ora_Base1.F_ora_Text", "F_ora_Base", "F_ora_Base.FName", "FEntryNote"
                , "FAUXPROPID.FF100001.fdatavalue"
                , "FAUXPROPID.FF100002.fdatavalue"
                , "FAUXPROPID.FF100003"
                , "FAUXPROPID.FF100004"
                , "FAUXPROPID.FF100005.fdatavalue"
                , "FAUXPROPID.FF100006.fdatavalue"
                , "FAUXPROPID.FF100007"
                , "FAUXPROPID.FF100008"
                , "FAUXPROPID.FF100009"
                , "FAUXPROPID.FF100011"
                , "FAUXPROPID.FF100013"
                , "FAUXPROPID.FF100015.fdatavalue"
                , "FAUXPROPID.FF100016.fdatavalue"
                , "FAUXPROPID.FF100017.fdatavalue"
                , "FAUXPROPID.FF100018.fdatavalue"
                , "FAUXPROPID.FF100019.fdatavalue"
                , "FAUXPROPID.FF100020.fdatavalue"
                , "FAUXPROPID.FF100021"
                , "FAUXPROPID.FF100022"
                , "FAUXPROPID.FF100023"
        };
        String where = "FStockOrgId = 100121 and FDate >= '2022-01-01'"
                + (StringUtils.isNotBlank(c) ? AND + c : "");
        return super.getDataJson("STK_OutStockApply", ArrayUtils.addAll(main_fields, detail_fields), where);
    }

}
